﻿using System;
using System.Collections.Generic;

namespace Nextensions.Text
{
    public class HuffmanCompression
    {
        public void BuildTrees(string Deflated)
        {
            byte[] charWeights = new byte[256];
            List<LinkedList<HuffmanNode>> listOfTrees = new List<LinkedList<HuffmanNode>>(64);

            int textLength = Deflated.Length;

            for (int i = 0; i < textLength; i++)
            {
                //LinkedList<char> tree = new LinkedList<char>();
                charWeights[Deflated[i]]++;
            }

            for (int i = 0; i < charWeights.Length; i++)
            {
                if (charWeights[i] > 0)
                {
                    LinkedList<HuffmanNode> tree = new LinkedList<HuffmanNode>();
                    tree.AddFirst(new HuffmanNode((char)i, charWeights[i]));
                    listOfTrees.Add(tree);
                }
            }
        }
    }

    public class HuffmanNode
    {
        public char Char;
        public int Weight;

        public HuffmanNode(char Char, int Weight)
        {
            this.Char = Char;
            this.Weight = Weight;
        }
    }
}
